<template>
  <div>
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="来源">
        <webQuerySource @source="sourceMethod"></webQuerySource>
      </el-form-item>
      <el-form-item>
        <el-switch v-model="isItemId" active-text="爱听歌曲id不为空" inactive-text="全部" @change="itemIdMethod"></el-switch>
      </el-form-item>
      <!--  <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item> -->
    </el-form>
    <el-table :data="songsItem" height="640" border style="width: 100%">
      <el-table-column type="index" width="80"></el-table-column>
      <el-table-column prop="song_name" label="歌曲名" width="180">
      </el-table-column>
      <el-table-column prop="artist" label="歌手" width="180">
      </el-table-column>
      <el-table-column prop="url_source" label="来源"></el-table-column>
      <el-table-column prop="itemid" label="爱听歌曲id" :filters="itemIdFilter" :filter-method="filterMethod"></el-table-column>
      <el-table-column prop="song_id" label="歌曲id"></el-table-column>
      <el-table-column prop="modify_date" label="修改时间"></el-table-column>
    </el-table>
    <el-pagination background layout="total, prev, pager, next, jumper" :total="total" :page-size="ps" @current-change="listMethod">
    </el-pagination>
  </div>
</template>
<script>
import apis from "@utils/apis";
import webQuerySource from "@comps/cms/WebQuerySource.vue";

export default {
  data() {
    return {
      pn: 1,
      ps: 1000,
      total: 0,
      isItemId: false,
      source: 'all',
      songsItem: [],
      itemIdFilter: [{
        text: 'itemid',
        value: null,
      }]
    }
  },

  components: {
    webQuerySource,
  },

  mounted() {
    this.listMethod()
  },

  methods: {
    listMethod(page) {
      let loading = this.$loading({
        lock: true,
        text: '数据加载中...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      this.pn = page || 1
      let params = {
        pn: this.pn,
        ps: this.ps,
        source: this.source,
        isItemId: this.isItemId,
      }
      apis.webSongsApi(params).then(res => {
        loading.close();
        this.total = res.result.total
        this.songsItem = res.result.docs
      })
    },

    filterMethod(value, row) {
      return row.itemid != value
    },

    sourceMethod(source) {
      this.source = source
      this.listMethod()
    },

    itemIdMethod() {
      this.listMethod()
    },
  }
}

</script>
